package com.zr.service.impl;

import com.zr.entity.StaffFile;
import com.zr.exception.MyFileNotFoundException;
import com.zr.mapper.StaffFileMapper;
import com.zr.service.StaffFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class StaffFileServiceImpl implements StaffFileService {

    @Autowired
    private StaffFileMapper mapper;

    /**
     * 根据员工Id查询文件信息
     * @param staffId
     * @return
     */
    @Override
    public List<StaffFile> queryFileById(Integer staffId) {
        return mapper.queryFileById(staffId);
    }

    /**
     * 根据Id文件信息
     * @param id
     * @return
     */
    @Override
    public StaffFile queryFileByteArray(Integer id) {
        StaffFile staffFile = mapper.queryFileByteArray(id);
        if (StringUtils.isEmpty(staffFile.getFileUrl())){
            throw new MyFileNotFoundException("未找到该文件：" + id);
        }
        return staffFile;
    }

}
